package com.download.zhuaba.Service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import java.util.Random;
@Service
public class MailService {
    //发送者
    @Value("${spring.mail.username}")
    private String sender;
    //发送邮件工具类
    @Autowired
    private JavaMailSender mailSender;

    //发送简单邮件
    public String sendSimpleMailMessage(String to,String subject){
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setTo(to);
        simpleMailMessage.setSubject(subject);
        simpleMailMessage.setFrom(sender);

        Random random = new Random();
        String content="";
        for (int i=0;i<6;i++)
        {
            content+=random.nextInt(10);
        }
        simpleMailMessage.setText("尊敬的用户您好,您本次注册的验证码是:" + content);
        mailSender.send(simpleMailMessage);
        return content;
    }
}
